﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Submit_Click(object sender, EventArgs e)
    {
        string name = Username.Text.Trim();
        string password = Password.Text.Trim();

        CmsDataContext db = new CmsDataContext();
        var q = from aM in db.Manager
                where aM.ID == name
                select aM;

        if (q.Count() == 0)
        {
            MessageBox.Message = "用户名输入错误，请重新输入。";
        }
        else if (password != q.First().Password)
        {
            MessageBox.Message = "密码输入错误，请重新输入。";
        }
        else
        {
            //获取用户权限
            int power = 0;
            //power = (from aP in db.Power
            //         where aP.ManagerID == q.First().ID
            //         select aP.Role.Authority).ToList().Aggregate((a, b) => a + b);
            
            Session["ManagerID"] = q.First().ID;
            Session["ManagerName"] = q.First().Name;
            Session["ManagementTheme"] = Toolkit.GetSettingValue("ManagementTheme");
            Session["ManagerPower"] = 1;

            Response.Redirect("~/Manage/Default.aspx");
        }
    }
}